asm
  ld sp,$5FFF
  end asm

#include "./library/pacmandelay.bas"
#include "./library/smsrnd.bas"

dim eee as uinteger at $5810
dim seed as uinteger at $5812
dim ee0 as uinteger at $5814
dim ee1 as uinteger at $5816
dim ee2 as uinteger at $5818
dim ee3 as uinteger at $581A
dim ee4 as uinteger at $581C
dim ee5 as uinteger at $581E
dim ee6 as uinteger at $5820
dim ee7 as uinteger at $5822
dim ex0 as uinteger at $5824
dim ey0 as uinteger at $5826

sub espialputchar(txp1 as uinteger,typ1 as uinteger,tch1 as ubyte,tat1 as ubyte, tcl1 as ubyte):
  poke $8400+typ1*32+txp1,tch1
  poke $8C00+typ1*32+txp1,tat1
  poke $9400+typ1*32+txp1,tcl1
  poke $7000,127
  end sub


for ee0=0 to 31
  for ee1=0 to 31
    ee2=seed:seed=smsrnd(seed)
    ee3=seed:seed=smsrnd(seed)
    ee2=seed:seed=smsrnd(seed)
    espialputchar(ee1,ee0,seed band 3,0,ee3)
    poke $7000,127
    next:next

for ee0=0 to 15
  for ee1=0 to 15
    ee2=seed:seed=smsrnd(seed)
    ee3=seed:seed=smsrnd(seed)
    ee2=seed:seed=smsrnd(seed)
    espialputchar(ee1+15,ee0+13,ee0*16+ee1,0,0)
    poke $7000,127
    next:next

eee=0:ex0=8:ey0=8
do

espialputchar(1,3,48+(int(eee/10000) mod 10),0,0)
espialputchar(2,3,48+(int(eee/1000) mod 10),0,0)
espialputchar(3,3,48+(int(eee/100) mod 10),0,0)
espialputchar(4,3,48+(int(eee/10) mod 10),0,0)
espialputchar(5,3,48+(eee mod 10),0,0)

ee0=peek($6081)
espialputchar(3,5,48+(int(ee0/100) mod 10),0,0)
espialputchar(4,5,48+(int(ee0/10) mod 10),0,0)
espialputchar(5,5,48+(ee0 mod 10),0,0)

ee0=peek($6082)
espialputchar(3,6,48+(int(ee0/100) mod 10),0,0)
espialputchar(4,6,48+(int(ee0/10) mod 10),0,0)
espialputchar(5,6,48+(ee0 mod 10),0,0)

ee0=peek($6083)
espialputchar(3,7,48+(int(ee0/100) mod 10),0,0)
espialputchar(4,7,48+(int(ee0/10) mod 10),0,0)
espialputchar(5,7,48+(ee0 mod 10),0,0)

ey0=ey0+((ee0 band 32)/32)

ee0=peek($6084)
espialputchar(3,8,48+(int(ee0/100) mod 10),0,0)
espialputchar(4,8,48+(int(ee0/10) mod 10),0,0)
espialputchar(5,8,48+(ee0 mod 10),0,0)

ex0=ex0-((ee0 band 128)/128)
ex0=ex0+((ee0 band 8)/8)
ey0=ey0-((ee0 band 16)/16)

espialputchar(ex0,ey0,eee band 127,0,0)

eee=eee+1
poke $7000,127
loop





do:poke $7000,127:loop




for ee0=0 to 31
  for ee1=0 to 31
    ee2=seed:seed=smsrnd(seed)
    ee3=seed:seed=smsrnd(seed)
    ee2=seed:seed=smsrnd(seed)
    espialputchar(ee1,ee0,seed,ee2,ee3)
    next:next

'do:loop

'for ee0=0 to 31
'  for ee1=0 to 31
'    ee2=seed:seed=smsrnd(seed)
'    ee3=seed:seed=smsrnd(seed)
'    ee2=seed:seed=smsrnd(seed)
'    poke $8400+(ee0*32)+ee1,seed
'    poke $8C00+ee0*32+ee1,ee2
'    poke $9400+ee0*32+ee1,ee3
'    'espialputchar(ee1,ee0,seed,ee2,ee3)
'    poke $7000,127
'    next:next





do

for eee=$8400 to $87FF '- videoram
  seed=smsrnd(seed)
  poke eee,seed
  pacmandelay(1000)
  poke $7000,127
  next
for eee=$8C00 to $8FFF '- attributeram
  seed=smsrnd(seed)
  poke eee,seed
  pacmandelay(1000)
  poke $7000,127
  next
for eee=$9400 to $97FF '- colorram
  seed=smsrnd(seed)
  poke eee,seed
  pacmandelay(1000)
  poke $7000,127
  next

for eee=$9020 to $903F '- scrollram
  seed=smsrnd(seed)
  poke eee,seed
  pacmandelay(10000)
  poke $7000,127
  next

for eee=$8000 to $801F '- spriteram1
  seed=smsrnd(seed)
  poke eee,seed
  poke $7000,127
  next
for eee=$9000 to $901F '- spriteram2
  seed=smsrnd(seed)
  poke eee,seed
  poke $7000,127
  next
for eee=$8800 to $880F '- spriteram3
  seed=smsrnd(seed)
  poke eee,seed
  poke $7000,127
  next


loop

do:loop

'static ADDRESS_MAP_START( espial_map, AS_PROGRAM, 8, espial_state )
'AM_RANGE(0x0000, 0x4fff) AM_ROM
'AM_RANGE(0x5800, 0x5fff) AM_RAM
'AM_RANGE(0x6081, 0x6081) AM_READ_PORT("IN0")
'AM_RANGE(0x6082, 0x6082) AM_READ_PORT("DSW1")
'AM_RANGE(0x6083, 0x6083) AM_READ_PORT("IN1")
'AM_RANGE(0x6084, 0x6084) AM_READ_PORT("IN2")
'AM_RANGE(0x6090, 0x6090) AM_READ(soundlatch2_byte_r) AM_WRITE(espial_master_soundlatch_w)
'AM_RANGE(0x7000, 0x7000) AM_READWRITE(watchdog_reset_r, watchdog_reset_w)
'AM_RANGE(0x7100, 0x7100) AM_WRITE(espial_master_interrupt_mask_w)
'AM_RANGE(0x7200, 0x7200) AM_WRITE(espial_flipscreen_w)
'AM_RANGE(0x8000, 0x801f) AM_RAM AM_SHARE("spriteram_1")
'AM_RANGE(0x8020, 0x803f) AM_READONLY
'AM_RANGE(0x8400, 0x87ff) AM_RAM_WRITE(espial_videoram_w) AM_SHARE("videoram")
'AM_RANGE(0x8800, 0x880f) AM_WRITEONLY AM_SHARE("spriteram_3")
'AM_RANGE(0x8c00, 0x8fff) AM_RAM_WRITE(espial_attributeram_w) AM_SHARE("attributeram")
'AM_RANGE(0x9000, 0x901f) AM_RAM AM_SHARE("spriteram_2")
'AM_RANGE(0x9020, 0x903f) AM_RAM_WRITE(espial_scrollram_w) AM_SHARE("scrollram")
'AM_RANGE(0x9400, 0x97ff) AM_RAM_WRITE(espial_colorram_w) AM_SHARE("colorram")
'AM_RANGE(0xc000, 0xcfff) AM_ROM
'ADDRESS_MAP_END



'
'sub pingpongputsprite(tlayer as ubyte,tx as ubyte,ty as ubyte,tid as ubyte,tclut as ubyte):
'  poke $9006+((tlayer band 15)*4),tx  '- x sprite 0
'  poke $9004+((tlayer band 15)*4),ty bxor 255  '- y sprite 0
'  poke $9005+((tlayer band 15)*4),tid          '- shape sprite 0
'  poke $9003+((tlayer band 15)*4),tclut        '- clut? sprite 0
'  end sub
'
'function test1(t1 as uinteger,t2 as uinteger,t3 as uinteger,t4 as uinteger)  as uinteger
'  end function
'
'sub zpoke(t1 as uinteger,t2 as ubyte)
'  poke t1,t2
'  end sub
'
'sub putchar(tx1 as uinteger, ty1 as uinteger, tch1 as uinteger)
'  poke ($8400+(tx1*32)+ty1) bxor %0000001111100000,(tch1 band 255)
'  end sub
'
'pingpongputsprite(0,21,10,4,3)
'pingpongputsprite(1,21,30,4,3)
'pingpongputsprite(2,21,50,4,3)
'pingpongputsprite(3,21,70,4,3)
'pingpongputsprite(4,21,90,4,3)
'pingpongputsprite(5,21,110,4,3)
'pingpongputsprite(6,21,130,4,3)
'pingpongputsprite(7,21,150,4,3)
'
'seed=0
'
'for ee2=64 to 1023-64
'  for ee3=1 to 100
'    poke $8400+ee2,$01
'    next:next
'
'ee4=0
'for ee2=3 to 3+15
'  for ee3=15 to 15+15
'    poke $8400+ee3+(ee2*32),ee4
'    ee4=ee4+1
'    next:next
'
'ee4=0
'for ee2=20 to 20+7
'  for ee3=15 to 15+15
'    poke $8400+ee3+(ee2*32),ee4 band 3
'    poke $8000+ee3+(ee2*32),int(ee4/4)
'    ee4=ee4+1
'    next:next
'
'
'
'
'for ee2=4 to 7
'  for ee3=2 to 5
'    poke $8400+ee3+(ee2*32),code("X")
'    next
'    next
'
'test1(377,2445,63888,2342)
'
'eee=$4207
'i=code("Q")
'poke eee,i
'eee=eee+1
'i=code("T")
'poke eee,i
'
'seed=0
'for eee=$4400 to $47FF
'  seed=smsrnd(seed)
'  poke eee,seed
'  next
'
'ex0=80:ey0=176
'
'eee=0
'ecsp=0:ecsq=0
'
'
'do
'poke $A600,255 '- watchdog? - it seems to work! thanks, Jim Bagley!!!!
'
'ej0=peek($A800) bxor $ff
'ej1=peek($A880) bxor $ff
'
'poke ($8400+(10*32)+6) bxor %0000001111100000,ej0
'poke ($8400+(10*32)+7) bxor %0000001111100000,ej1
'
'poke ($8400+(12*32)+8) bxor %0000001111100000,48+(ex0 mod 10)
'poke ($8400+(12*32)+7) bxor %0000001111100000,48+((int(ex0/10)) mod 10)
'poke ($8400+(12*32)+6) bxor %0000001111100000,48+((int(ex0/100)) mod 10)
'
'poke ($8400+(13*32)+8) bxor %0000001111100000,48+(ey0 mod 10)
'poke ($8400+(13*32)+7) bxor %0000001111100000,48+((int(ey0/10)) mod 10)
'poke ($8400+(13*32)+6) bxor %0000001111100000,48+((int(ey0/100)) mod 10)
'
'poke ($8400+(14*32)+8) bxor %0000001111100000,48+(eee mod 10)
'poke ($8400+(14*32)+7) bxor %0000001111100000,48+((int(eee/10)) mod 10)
'poke ($8400+(14*32)+6) bxor %0000001111100000,48+((int(eee/100)) mod 10)
'poke ($8400+(14*32)+5) bxor %0000001111100000,48+((int(eee/1000)) mod 10)
'poke ($8400+(14*32)+4) bxor %0000001111100000,48+((int(eee/10000)) mod 10)
'
'poke ($8400+(15*32)+8) bxor %0000001111100000,48+(ej0 mod 10)
'poke ($8400+(15*32)+7) bxor %0000001111100000,48+((int(ej0/10)) mod 10)
'poke ($8400+(15*32)+6) bxor %0000001111100000,48+((int(ej0/100)) mod 10)
'
'poke ($8400+(16*32)+8) bxor %0000001111100000,48+(ej1 mod 10)
'poke ($8400+(16*32)+7) bxor %0000001111100000,48+((int(ej1/10)) mod 10)
'poke ($8400+(16*32)+6) bxor %0000001111100000,48+((int(ej1/100)) mod 10)
'
'poke ($8400+(17*32)+8) bxor %0000001111100000,48+(ecsp mod 10)
'
'if (ej1 band 64)<>0 then: ex0=ex0+1:end if
'if (ej1 band 32)<>0 then: ex0=ex0-1:end if
'if (ej1 band 4)<>0 then: ey0=ey0+1:end if
'if (ej1 band 2)<>0 then: ey0=ey0-1:end if
'
'if (ej1 band 15)<>0 then: ecsq=ecsq+1:end if
'ecsp=(int(ecsq/4))mod 8
'
'ee3=int(eee/4)
'
'pingpongputsprite( 0,ex0   ,ey0   ,4,3)  '- layer,x,y,id,clut
'pingpongputsprite( 1,ex0+16,ey0   ,4,3)  '- layer,x,y,id,clut
'pingpongputsprite( 2,ex0+32,ey0   ,4,3)  '- layer,x,y,id,clut
'pingpongputsprite( 3,ex0+48,ey0   ,4,3)  '- layer,x,y,id,clut
'pingpongputsprite( 4,ex0   ,ey0+16,4,3)  '- layer,x,y,id,clut
'pingpongputsprite( 5,ex0+16,ey0+16,4,3)  '- layer,x,y,id,clut
'pingpongputsprite( 6,ex0+32,ey0+16,4,3)  '- layer,x,y,id,clut
'pingpongputsprite( 7,ex0+48,ey0+16,4,3)  '- layer,x,y,id,clut
'pingpongputsprite( 8,ex0   ,ey0+32,4,3)  '- layer,x,y,id,clut
'pingpongputsprite( 9,ex0+16,ey0+32,4,3)  '- layer,x,y,id,clut
'pingpongputsprite(10,ex0+32,ey0+32,4,3)  '- layer,x,y,id,clut
'pingpongputsprite(11,ex0+48,ey0+32,4,3)  '- layer,x,y,id,clut
'pingpongputsprite(12,ex0   ,ey0+48,4,3)  '- layer,x,y,id,clut
'pingpongputsprite(13,ex0+16,ey0+48,4,3)  '- layer,x,y,id,clut
'pingpongputsprite(14,ex0+32,ey0+48,4,3)  '- layer,x,y,id,clut
'pingpongputsprite(15,ex0+48,ey0+48,4,3)  '- layer,x,y,id,clut
'
'
'eee=eee+1
'loop
'
''-------------------------------------------------------------------------------
'
'text01:
'asm
'  defb "HELLO WORLD!!!!!"
'  end asm
'
''-------------------------------------------------------------------------------
'
'
